<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.webshop.domain.user.User" %>
<%@ page import="com.webshop.domain.Items" %><%--
  Created by IntelliJ IDEA.
  User: jxdck662
  Date: 2019/8/15
  Time: 13:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>${sessionScope.user.name}的主页</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <style type="text/css">
        .col div{
            margin: 20px;
        }
        #row .col{
            padding-top: 12px;
            padding-bottom: 12px;
            border: 1px solid #000000;
        }
    </style>
</head>
<body>
<!-- header -->
<div class="container-fluid" >
    <div class="row">
        <div class="col-4"><img src="img/logo2.png" ></div>
        <div class="col-5"><img src="img/header.jpg" ></div>
        <div class="col">
            <c:if test="${sessionScope.user == null}">
                <div class="btn-group float-right" role="group" style="margin-top: 11px;">
                    <a href="LoginServlet"><button type="button" class="btn btn-outline-success">登录</button></a>
                    <a href="register.jsp"><button type="button" class="btn btn-outline-info">注册</button></a>
                    <a href="cart.jsp"><button type="button" class="btn btn-outline-secondary">购物车</button> </a>
                </div>
            </c:if>
            <c:if test="${sessionScope.user != null}">
                <div class="btn-group float-right" role="group" style="margin-top: 11px;">
                    <a href="GetUserServlet"><button type="button" class="btn btn-outline-success">${sessionScope.user.name}</button></a>
                    <a href="LogoutServlet"><button type="button" class="btn btn-outline-info">退出</button></a>
                    <a href="cart.jsp"><button type="button" class="btn btn-outline-secondary">购物车</button> </a>
                    <a href="./GetBusServlet"><button type="button" class="btn btn-outline-danger">我的订单</button> </a>
                </div>
            </c:if>
        </div>
    </div>
</div>
<!-- nav -->
<div class="container-fluid border border-primary" >
    <nav class="navbar navbar-dark bg-dark">
        <nav class="nav nav-pills">
            <c:forEach var="i" begin="0" end="${Items.size}">
                <a class="nav-link text-light" href="items.jsp?pclass=${i}&n=1">${Items.allclass[i]}</a>
            </c:forEach>
            <a class="nav-link text-light" href="index.jsp">首页</a>
        </nav>
        <form class="form-inline my-2 my-lg-0 " action="Search" method="post">
            <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search" name="search">
            <button class="btn btn-outline-light my-2 my-sm-0" type="submit">Search</button>
        </form>
    </nav>
</div>
<!-- 用户 -->
<div class="container">
    <div class="container-fluid border border-dark text-light text-lg-left" style="background-color: gray; margin-top: 10px;">用户信息</div>
    <form action="ChangeServlet" method="post" class="border border-secondary" id="info">
        <div class="form_group" style="margin-top: 10px; margin-bottom: 10px; font-size: 20px;">
            name:<input type="text" name="name" id="name" class="form-control" value="${sessionScope.user.name}" disabled="disabled"/>
        </div>
        <div class="form_group" style="margin-top: 10px; margin-bottom: 10px; font-size: 20px;">
            email:<input type="text" name="email" id="email" class="form-control" value="${sessionScope.user.email}" disabled="disabled"/>
        </div>
        <div class="form_group">
            tel <input type="text" name="tel" id="tel" class="form-control" value="${sessionScope.user.tel}" disabled="disabled"/>
        </div>
        <div class="form_group">
            birthday<input type="text" name="bir" id="bir" class="form-control" value="${sessionScope.user.birthday}" disabled="disabled"/>
        </div>
        <button type="button" onclick="fn()" id="button">点我更改</button>
    </form>
</div>
<%--商家--%>
<c:if test="${sessionScope.user.modify ne 'normal'}">
    <div class="container">
        <div class="container-fluid border border-dark text-light text-lg-left" style="background-color: gray; margin-top: 10px;">商家信息</div>
        <div class="row" id="row">
            <div class="col">名称</div>
            <div class="col">价格</div>
            <div class="col">类别</div>
            <div class="col">操作</div>
            <c:if test="${sessionScope.myitems ne null}">
                <c:forEach items="${sessionScope.myitems}" var="item">
                    <div class="w-100"></div>
                    <div class="col">${item.pname}</div>
                    <div class="col">${item.pprice}</div>
                    <div class="col">${item.pclass}</div>
                    <div class="col"><a href="change.jsp?id=${item.id}">更新</a> <a href="./DeleteServlet?id=${item.id}&userid=${sessionScope.user.userid}">删除</a></div>
                </c:forEach>
            </c:if>
            <c:if test="${sessionScope.myitems eq null}">
                <div class="w-100"></div>
                <div class="col">无</div>
            </c:if>
            <div class="w-100"></div>
            <div class="col"><a href="add.jsp"><button>添加</button></a></div>
        </div>
    </div>
</c:if>
<!-- footer -->
<div class="container-fluid" >
    <nav class="nav justify-content-center">
        <a class="nav-link">关于我们</a>
        <a class="nav-link">联系我们</a>
        <a class="nav-link">招贤纳士</a>
        <a class="nav-link">法律声明</a>
        <a class="nav-link">友情链接</a>
        <a class="nav-link" target="_blank">支付方式</a>
        <a class="nav-link" target="_blank">配送方式</a>
        <a class="nav-link">服务声明</a>
        <a class="nav-link">广告声明</a>
    </nav>
</div>
<div style="text-align: center;margin-top: 5px;margin-bottom:20px;">
    Copyright &copy; 2005-2016 传智商城 版权所有
</div>
<script src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
    function fn(){
        $("form input").removeAttr("disabled");
        $("#bir").attr("type","date")
        $("#info").append("<button type=\"submit\" id=\"submit\" onclick=\"fn1()\">提交</button>")
    }
    function fn1(){
        var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
        var fg1 = ($("#name").val() == "");
        // var fg2 = reg.test($("#email").val());
        var fg3 = ($("#tel").val() == "");
        if( fg1)
            alert("昵称不能为空");
        // if (fg2)
        //     alert("填写正确的邮箱格式");
        if (fg3)
            alert("电话不能为空");


        if(!fg1 && !fg3){
            $("#info").submit();
        }
    }
</script>
</body>
</html>
